package com.develop.archives.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.develop.archives.domain.CompactDO;
import com.develop.archives.service.CompactService;
import com.develop.common.utils.PageUtils;
import com.develop.common.utils.Query;
import com.develop.common.utils.R;



/**
 * 
 * 
 * @author chglee
 * @email 1992lcg@163.com
 * @date 2019-04-08 14:45:27
 */
 
@Controller
@RequestMapping("archives/compact")
public class CompactController {
	String prefix = "archives/compact";
	@Autowired
	private CompactService compactService;
	
	@GetMapping()
	@RequiresPermissions("archives:compact:compact")
	String Compact(){
	    return "archives/compact/compact";
	}
	
	@ResponseBody
	@GetMapping("/list")
	@RequiresPermissions("archives:compact:compact")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<CompactDO> compactList = compactService.list(query);
		int total = compactService.count(query);
		PageUtils pageUtils = new PageUtils(compactList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("archives:compact:add")
	String add(){
	    return "archives/compact/add";
	}

	@GetMapping("/edit/{compactnum}")
	@RequiresPermissions("archives:compact:edit")
	String edit(@PathVariable("compactnum") String compactnum,Model model){
		CompactDO compact = compactService.get(compactnum);
		model.addAttribute("compact", compact);
	    return "archives/compact/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("archives:compact:add")
	public R save( CompactDO compact){
		if(compactService.save(compact)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("archives:compact:edit")
	public R update( CompactDO compact){
		compactService.update(compact);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("archives:compact:remove")
	public R remove( String compactnum){
		if(compactService.remove(compactnum)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("archives:compact:batchRemove")
	public R remove(@RequestParam("ids[]") String[] compactnums){
		compactService.batchRemove(compactnums);
		return R.ok();
	}
	
}
